package com.brianxia.quickredis.utils;

import com.brianxia.quickredis.exception.QuickRedisException;

import java.io.UnsupportedEncodingException;

/**
 * Created by wangyijie on 17/5/23.
 */
public final class EncodeUtils {

    public static byte[]  encode(final String src){

        if(src == null)
            throw new QuickRedisException("string to encode can not be null!");

        try {
            return src.getBytes("UTF-8");
        } catch (UnsupportedEncodingException e) {
            throw new QuickRedisException("encode to UTF8 error!");
        }
    }


    public static String  encode(final byte [] bt){

        try {
            return new String(bt,"UTF-8");
        } catch (UnsupportedEncodingException e) {
            throw new QuickRedisException("error to String");
        }
    }
}
